Check if a Number is Positive, Negative, or Zero

Theory:

A number is positive if it is greater than zero, negative if it is less than zero, and zero if it is equal to zero.

Python Code:

def check_number(num):
    if num > 0:
        return "Positive"
    elif num < 0:
        return "Negative"
    else:
        return "Zero"

# Taking input for the number and checking its sign
def check_and_display_number_sign():
    num = float(input("Enter a number: "))
    sign = check_number(num)
    print("The number is", sign)

check_and_display_number_sign()

Example Output 1:

Enter a number: 5

The number is Positive

Example Output 2:

Enter a number: -2

The number is Negative

Example Output 3:

Enter a number: 0

The number is Zero

Code Explanation:

The function check_number(num) checks whether a given number is positive, negative, or zero, and returns the corresponding string.

The function check_and_display_number_sign() takes input for the number, checks its sign using the aforementioned function, and displays the result.